﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using System.Text;
public partial class bgDate_DayValue : System.Web.UI.Page
{
    string id;
    string unit;
    string time;
    string repName;

    BLLData da = new BLLData();
    StringBuilder sb = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        string sql;

        if (!IsPostBack)
        {
            repName = Request.QueryString["repName"];
            unit = Request.QueryString["uint"];
            time = Request.QueryString["time"];
            id = Request.QueryString["IDKEY"];

            this.hID.Value = id;
            this.hTime.Value = time;
            this.jz.Value = unit;

            DateTime dt = DateTime.Now;

            if (DateTime.Parse(time) <= dt)
            {
                string qsrq;
                string jsrq;

                qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
                jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

                DataRow dr = da.RetDataRowByID(id);

                DataTable dtt = da.RetBzValue(dr["小时点"].ToString(), unit, dr["参数类型"].ToString(), qsrq, jsrq);

                if (dtt != null && dtt.Rows.Count > 0)
                {
                    for (int i = 0; i < dtt.Rows.Count; i++)
                    {
                        sb.Append("<tr>");

                        sb.AppendFormat("<td align='center' id ='" + dr["参数名"] + "'>{0}</td>", dr["参数名"]);

                        sb.AppendFormat("<td align='center'>{0}</td>", dtt.Rows[i]["统计ID"].ToString());

                        sb.AppendFormat("<td align='center'>{0}</td>", dtt.Rows[i]["时间"].ToString());

                        sb.AppendFormat("<td align='center'><input type=\"text\" id=\"txtValue" + i + "\" value='{0}' class=\"nvinput\" /></td>", dtt.Rows[i]["统计值"].ToString());

                        sb.AppendFormat("<td align='center'><input type=\"hidden\" id=\"BZ" + i + "\" value='{0}' class=\"nvinput\" readonly />{0}</td>", dtt.Rows[i]["班组"].ToString());

                        sb.Append("</tr>");
                    }

                    this.tjID.Value = dtt.Rows[0]["统计ID"].ToString();
                }

                this.show.InnerHtml = sb.ToString();
            }
            else
            {
                Jscript.Alert("请选择正确日期！");
                this.Response.Write("<script language=javascript>window.close();</script>");
            }
        }
    }

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id = this.hID.Value;
        string jz = this.jz.Value;
        string time = this.hTime.Value;
        string tjID = this.tjID.Value;

        string[] val = new string[5];
        string[] bz = new string[5];

        bz[0] = this.hid1.Value;
        bz[1] = this.hid2.Value;
        bz[2] = this.hid3.Value;
        bz[3] = this.hid4.Value;
        bz[4] = this.hid5.Value;

        val[0] = this.Hidden1.Value;
        val[1] = this.Hidden2.Value;
        val[2] = this.Hidden3.Value;
        val[3] = this.Hidden4.Value;
        val[4] = this.Hidden5.Value;

        bool flag = da.RetIsTrueToSavaBz(id, jz, time, tjID, val, bz);

        if (flag == true)
            Jscript.AlertAndCloseWindow("保存成功!");
        else
            Jscript.Alert("保存失败!");
    }
}
